import { treetolist, list2Tree } from '@/utils/list2tree'
import { getMenuListAPI } from '@/api/menus'
const state = () => {
  return {
    perDate: ''
  }
}

const mutations = {
  // 存储树形数据
  setPerDate: (state, date) => {
    state.perDate = date
  }
}

const actions = {
  async getPermissionTree({ commit }) {
    const resp = await getMenuListAPI()
    const arrList = treetolist(resp.data)
    arrList.push({
      title: '系统菜单和权限点',
      pid: 0,
      id: null
    })
    const menuList = list2Tree(arrList, 0)
    commit('setPerDate', menuList)
  }
}
export default {
  // 开启命名空间
  namespaced: true,
  state,
  mutations,
  actions
}
